Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: treat void as null for null coalescing operator #2494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kesselb wants to merge 1 commit into phpstan:1.11.x from kesselb:void-nullcoalesce

Conversation

@kesselb
Copy link

@kesselb kesselb commented Jun 28, 2023

Hi 👋

WordPress often uses type definitions like array|void (e.g. https://github.com/WordPress/wordpress-develop/blob/68be569925ad2a88c97e1308b8a67a57bf17a14f/src/wp-includes/post.php#L2627).

$custom_keys = get_post_custom_keys( $post_id ) ?? [];

Shows: Expression on left side of ?? is not nullable.

Copy link
Collaborator

You've opened the pull request against the latest branch 1.11.x. If your code is relevant on 1.10.x and you want it to be released sooner, please rebase your pull request and change its target to 1.10.x.

Copy link
Member

Using void in a union is completely invalid and when used in a native type even crashes PHP: https://3v4l.org/7iULB

Instead of array|void instead array|null should be used.

That said, I'd accept a PR that changes array|void into array|null as a result of FuncCall/StaticCall/MethodCall. So the change needs to happen in MutatingScope::resolveType. It's not enough to change a single rule.

mvorisek reacted with thumbs up emoji

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Copy link
Author

kesselb commented Jun 28, 2023

Thanks for your prompt review 👍

I will take a look.

Copy link
Contributor

herndlm commented Jun 28, 2023
edited
Loading

Looks like you are aware of it already @kesselb , but just for the sake of completeness and issue linking - we discussed this also in szepeviktor/phpstan-wordpress#176, and yeah, WordPress types are wrong there IMO

Oh and phpstan/phpstan#9185 too

Copy link
Member

Superseded by #2778

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /